import {useState} from 'react';

/**
 * 布尔开关
 * @param init
 */
const useSwitch = (init: boolean = false): [boolean, Turn] => {
    const [switcher, setSwitcher] = useState(init);
    const turnOn = () => setSwitcher(true);
    const turnOff = () => setSwitcher(false);
    return [switcher, {turnOn, turnOff}];
}

export default useSwitch;

export interface Turn {

    /**
     * 打开
     */
    turnOn: () => void;

    /**
     * 关闭
     */
    turnOff: () => void;

}
